home *** CD-ROM | disk | FTP | other *** search
- unit RASBase;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
-
- type
- TRASBaseComponent = class (TComponent)
- private
- { Private declarations }
- fErrorText: String;
- fError: Integer;
- fOnError: TNotifyEvent;
- fRasLib, fRasExtensionsLib: THandle;
- fWin2000, fWinNT4, fAvailable, fDummy1: Boolean;
- protected
- function GetProc (ProcName: PChar): Pointer;
- function CallProc (Err: Integer): Boolean;
- property Win2000: Boolean read fWin2000;
- property WinNT4: Boolean read fWinNT4;
- public
- { Public declarations }
- constructor Create (AOwner: TComponent); override;
- destructor Destroy; override;
- property ErrorText: String read fErrorText;
- property Error: Integer read fError;
- published
- { Published declarations }
- property Available: Boolean read fAvailable write fDummy1 stored False;
- property OnError: TNotifyEvent read fOnError write fOnError;
- end;
-
- implementation
-
-
- // TRASBaseComponent
-
- constructor TRASBaseComponent.Create (AOwner: TComponent);
- begin
- Inherited Create (AOwner);
- fRasLib := LoadLibrary ('rasapi32.dll');
- fRasExtensionsLib := LoadLibrary ('rnaph.dll');
- fAvailable := fRasLib <> 0;
- fWin2000 := (Win32Platform = Ver_Platform_Win32_NT) and (Win32MajorVersion >= 5);
- fWinNT4 := (Win32Platform = Ver_Platform_Win32_NT) and (Win32MajorVersion = 4);
- end;
-
- destructor TRASBaseComponent.Destroy;
- begin
- if fRasLib <> 0 then FreeLibrary (fRasLib);
- if fRasExtensionsLib <> 0 then FreeLibrary (fRasExtensionsLib);
- Inherited;
- end;
-
- function TRASBaseComponent.GetProc (ProcName: PChar): Pointer;
- begin
- Result := Nil;
- if fAvailable then begin
- Result := GetProcAddress (fRasLib, ProcName);
- if (Result = Nil) and (fRasExtensionsLib <> 0) then
- Result := GetProcAddress (fRasExtensionsLib, ProcName);
- end;
- end;
-
- function TRASBaseComponent.CallProc (Err: Integer): Boolean;
- var
- szErr: array [0..1024] of Char;
- RasGetErrorString: function (Err: Integer; Buff: PChar; BuffSize: Integer): Integer; stdcall;
- begin
- fError := Err; Result := Err = 0;
- if Result then fErrorText := '' else begin
- RasGetErrorString := GetProc ('RasGetErrorStringA');
- if RasGetErrorString (Err, szErr, sizeof (szErr)) = 0 then fErrorText := szErr else begin
- fErrorText := SysErrorMessage (Err);
- if fErrorText = '' then fErrorText := Format ('Unknown error (%d)', [Err]);
- end;
-
- fErrorText := 'RAS: ' + fErrorText;
- if Assigned (fOnError) then fOnError (Self);
- end;
- end;
-
- end.
-